package com.hrm.dao;

import com.hrm.entity.EmployeeEntity;
import com.hrm.util.PasswordUtil;
import org.apache.commons.collections.map.HashedMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Create by zekdot on 20-2-24.
 */
public class EmployeeDao extends BaseDao<EmployeeEntity> {

    /**
     * 获取所有雇主
     * @return
     * @throws Exception
     */
    public List<EmployeeEntity> getEmployers() throws Exception {
        String sql = "SELECT * FROM employee WHERE auth='y'";
        return queryList(sql);
    }

    /**
     * 获取本部门所有雇员
     * @param dep
     * @return
     */
    public List<EmployeeEntity> getUnderEmployee(String dep) throws Exception {
        String sql = "SELECT * FROM employee WHERE auth ='n' AND department=?";
        Object[] params = {dep};
        return queryList(sql,params);
    }

    public static void main(String args[]){
        EmployeeDao employeeDao = new EmployeeDao();
        try {
//            System.out.println(employeeDao.getEmployers());
            System.out.println(employeeDao.getUnderEmployee("产品研发部"));
        } catch (Exception e) {
            e.printStackTrace();
        }
//        EmployeeEntity employeeEntity = new EmployeeEntity();
//        employeeEntity.setId("00011234");
//        employeeEntity.setPassword("123456");
//        employeeEntity.setName("zekdot");
//        employeeEntity.setGender("男");
//        employeeEntity.setAge(10);
//        employeeEntity.setContact("13912345678");
//        employeeEntity.setDepartment("软件学院");
//        employeeEntity.setPosition("院长");
//        employeeEntity.setStatus(0);
//        try {
//            employeeDao.save(employeeEntity);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        EmployeeEntity employeeEntity = null;
//        try {
////            employeeEntity = employeeDao.get("00011234");
////            employeeEntity.setContact("18312345678");
////            employeeDao.updateBaseInfo(employeeEntity);
//            Map<String,Object> map = new HashedMap();
//            map.put("contact","13912345678");
//            employeeDao.update("00011234",map);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println(employeeEntity.getContact());
    }
}
